import request from '../../utils/request'
// pages/index/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    bannerList:[],
    recomendList:[],
    rankList:[],
  },
  goPage(){
    wx.navigateTo({
      url: "/pages/recommend/recommend",
    })
  },
  async getRecomendList(){
    const rs = await request('/personalized',{limit:10})
    // {
    // alg: "alg_high_quality"
    // canDislike: true
    // copywriter: ""
    // highQuality: false
    // id: 2209538297
    // name: "「轻音乐·安静」舒缓放松，缓解压力"
    // picUrl: "https://p2.music.126.net/zQsuZvhJygPTFTM_FFnqhQ==/109951164139588912.jpg"
    // playCount: 10587697
    // trackCount: 99
    // trackNumberUpdateTime: 1659422719330
    // type: 0
    // }
    console.log('==>>',rs.result)
    if(rs.code === 200){
      this.setData({
        recomendList:rs.result
      })
    }
  },
  // 获取轮播图片
  async getBannerList(){
    const rs = await  request('/banner',{type:2})
      if(rs.code === 200){
        console.log(rs.banners)
      this.setData({
        bannerList: rs.banners
      })
    }
  },
  async getRankList(){
    let idx = 0;
    let rankList = [];
    while(idx<5){
      const rs = await request('/top/list',{idx:idx++})
      let obj = {
        id: rs.playlist.id,
        name: rs.playlist.name,
        songs: rs.playlist.tracks.slice(0,3)
      }
      rankList.push(obj)
      this.setData({
        rankList
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getBannerList();
    this.getRecomendList();
    this.getRankList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})